package net.molchat.android.scrn.btn;


import android.graphics.Canvas;
import android.graphics.Paint;


/**
 * Graphic button.
 * 
 * @author Valentine
 * 
 */
public class Button {

//==================================================================== Constants
// Warning! State constants must not exceed BtnStyle arrays length.
public static final byte ST_NORMAL = 0; // State normal 
public static final byte ST_SEL = 1; // State selected 
public static final byte ST_PRESS = 2; // State pressed


//======================================================================= Fields
// Coordinates and size
public int x;
public int y;
public int h;
public int w;

// Style
public BtnStyle style;
private final Paint paint;

// State
public boolean fEnabled = true;
public byte stateNum = ST_NORMAL;

// Command
public int com = -1;


//================================================================== Constructor
public Button() {

	style = new BtnStyle();
	paint = new Paint();
	paint.setStrokeWidth(0);
}


//===================================================================== hasPoint
//public boolean hasPoint(int x, int y) {
//
//	if (x < this.x || y < this.y || x > (this.x + this.w)
//			|| y > (this.y + this.h)) {
//		return false;
//	} else {
//		return true;
//	}
//}

//====================================================================== setSize 
public void setSize(int w, int h) {

	this.w = w;
	this.h = h;
}


//========================================================================= draw 
public void draw(Canvas g) {

	// TODO port this method properly
	paint.setColor(style.colBtn[stateNum]);
	g.drawRect(x, y, x + w, y + h, paint);

	if (style.icon != null) {
		int offset;
		if (stateNum == ST_PRESS) {
			offset = 1;
		} else {
			offset = 0;
		}
		//		g.drawImage(style.icon, x + (w >> 1) + offset, y + (h >> 1) + offset,
		//				Graphics.VCENTER | Graphics.HCENTER);
	}

	//	g.setColor(style.colLineBR[stateNum]);
	//	g.drawLine(x, y + h, x + w, y + h);
	//	g.drawLine(x + w, y, x + w, y + h);
	//	g.setColor(style.colLineTL[stateNum]);
	//	g.drawLine(x, y, x + w, y);
	//	g.drawLine(x, y, x, y + h);
}


//================================================================== setSelected 
public void setState(byte stateNum) {

	this.stateNum = stateNum;
}


}
